@extends('layouts.modal')

@section('content')
    <div id="roleGrant"></div>
    <input type="hidden" id="roleValue" value="{{ $default_premission}}">
    <script type="text/javascript">
        layui.use('tree', function () {
            var tree = layui.tree;
            var roleGrant = tree.render({
                id: "roleGrant",
                elem: "#roleGrant",
                oncheck: function (obj) {
                    var checkData = tree.getChecked('roleGrant');
                    var roleValueArr = getChildNodes(checkData, []);
                    $("#roleValue").val(roleValueArr.toString())
                },
                accordion: true,
                showCheckbox: true,
                data: {!! $data !!}
            });

            var premission = "{{ $default_premission }}";
            tree.setChecked('roleGrant', premission.split(","));
        });


        function getChildNodes(treeNode, result) {
            for (var i in treeNode) {
                result.push(treeNode[i].id);
                result = getChildNodes(treeNode[i].children, result);
            }
            return result;
        }

    </script>
@endsection
